package com.jixiantubu.yueban;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.example.jixiantubu.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jixiantubu.adapter.Ac_Mulu_Adapter;
import com.jixiantubu.bean.Ac_Bean;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class YueBan_MuLu_ZhouMo extends Activity implements OnClickListener {
	private ListView yueban_zhoumo;
	private ImageView ac_mulu_back;
	private TextView muluTitle;
	private MyApplication application;
	private Ac_Mulu_Adapter adapter;
	private Context context;
	private int number = 1;// 默认第一页
	private List<Ac_Bean> list = new ArrayList<Ac_Bean>();
	private String url = "http://" + MyApplication.getIP()
			+ ":8080/Jinnang/YueBan_Middle";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Window window = this.getWindow();
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.ac_mulu);
		initViews();
		initData();
	}
	private void initData() {
		adapter = new Ac_Mulu_Adapter(list, YueBan_MuLu_ZhouMo.this);
		yueban_zhoumo.setAdapter(adapter);
		// 绑定参数
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("key", "3");
		params.addQueryStringParameter("week", "1");
		HttpUtils httpUtils = new HttpUtils();
		httpUtils.send(HttpMethod.GET, url, params,
				new RequestCallBack<String>() {
					@Override
					public void onFailure(HttpException arg0, String arg1) {
						// 请求失败
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						// 请求成功
						String result = arg0.result;
						Gson gson = new Gson();
						Type type = new TypeToken<List<Ac_Bean>>() {
						}.getType();
						list = gson.fromJson(result, type);
						adapter.setList(list);
						adapter.notifyDataSetChanged();
					}

				});
		
	}
	private void initViews() {
		muluTitle=(TextView) findViewById(R.id.ac_mulu_title);
		muluTitle.setText("周末活动");
		yueban_zhoumo = (ListView) findViewById(R.id.yueban_mulu);
		ac_mulu_back = (ImageView) findViewById(R.id.ac_mulu_back);
		ac_mulu_back.setOnClickListener(this);
		yueban_zhoumo.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(YueBan_MuLu_ZhouMo.this,
						YueBan_XiangQing.class);
				intent.putExtra("ac", list.get(arg2));
				startActivity(intent);
			}
		});
		
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ac_mulu_back:
			finish();
			break;
		
		default:
			break;
		}
		
		
	}
}
